/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cms.dataaccess.hibernate;

import cms.dataaccess.ConferenceItemDAO;
import cms.exceptions.HibernateAccessLayerException;
import dto.Conferenceitem;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author eichawsan
 */
public class ConferenceItemDAOImpl extends AbstractDAO implements ConferenceItemDAO {

     public ConferenceItemDAOImpl(){
        super();
    }
 
    @Override
    public List<Conferenceitem> findAllConferenceitem() throws HibernateAccessLayerException {
        try {
            List returnvalue = super.findAll(Conferenceitem.class);
            return returnvalue;
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
        }
        
    }
    
    @Override
    public void insertConferenceItem(Conferenceitem conferenceItem) throws HibernateAccessLayerException {
        try {
            super.saveOrUpdate(conferenceItem);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }
    
    @Override
    public void updateConferenceItem(Conferenceitem conferenceItem) throws HibernateAccessLayerException {
         try {
            super.saveOrUpdate(conferenceItem);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
        
    }
    
    @Override
    public void deleteConferenceItem(Conferenceitem conferenceItem) throws HibernateAccessLayerException {
        try {
            // Logger.get// Logger(getClass().getName()).log(Level.INFO, "Deleting Conferenceitem" + conferenceItem.getItemDescription());
            super.delete(conferenceItem);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    
    @Override
    public Conferenceitem findConferenceItem(String conferenceName, String itemName) throws HibernateAccessLayerException {
         
       List<Conferenceitem> allListItem  = findAllConferenceitem();
       for(int i = 0; i < allListItem.size();i++){
            Conferenceitem item = allListItem.get(i);
            if(item.getId().getConferenceName().equals(conferenceName) 
                    && item.getId().getItemName().equals(itemName)){
               return item;
            }
           
       }
       return null;
    }
      
      
     @Override
    public List<Conferenceitem> findConferenceItemByConferenceName(String conferenceName) throws HibernateAccessLayerException {
           
       List<Conferenceitem> allListItem  = findAllConferenceitem();
       ArrayList<Conferenceitem> resultItem = new ArrayList<Conferenceitem>();
       for(int i = 0; i < allListItem.size();i++){
            Conferenceitem item = allListItem.get(i);
            if(item.getId().getConferenceName().equals(conferenceName) ){
                resultItem.add(item);
            }
           
       }
       return resultItem;
    }
     
     
    @Override
    public List<Conferenceitem> findConferenceItemByItemName(String itemName)
            throws HibernateAccessLayerException {
       List<Conferenceitem> allListItem  = findAllConferenceitem();
       ArrayList<Conferenceitem> resultItem = new ArrayList<Conferenceitem>();
       for(int i = 0; i < allListItem.size();i++){
            Conferenceitem item = allListItem.get(i);
            if(item.getId().getConferenceName().equals(itemName) ){
                resultItem.add(item);
            }
           
       }
       return resultItem;
    }

    @Override
    public List<Conferenceitem> findByCustomizeQuery(String queryString) throws HibernateAccessLayerException {
          return (List<Conferenceitem>) (this.findByCustomizeQuery(Conferenceitem.class, queryString));
         
    }
      
}
